﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using Model;
using BLL;

namespace OA.Controllers
{
    public class DesktopController : Controller
    {
        //
        // GET: /Desktop/
         
        public ActionResult Index()
        {
            Session["memberId"] = null;
            return View();
        }

        public ActionResult wastebookLoad(FormCollection fc)
        {
            string memberId = fc["memberId"].ToString();
            int numPage = Convert.ToInt32(fc["numPage"]);
            wasteBookManager waste = new wasteBookManager();
            Model.wasteBook wasteModel = new Model.wasteBook();
            List<wasteBook> list = new List<wasteBook>();
            list = waste.GetAll(memberId);
            StringBuilder sb = new StringBuilder();
            consumeSolutionManager consume = new consumeSolutionManager();
            consumeSolution consumeMode = new consumeSolution();
            sb.Append("<tr>");
            sb.Append("<th>流水号</th>");
            sb.Append("<th>操作员</th>");
            sb.Append("<th>会员编号</th>");
            sb.Append("<th>时间</th>");
            sb.Append("<th>会员类型</th>");
            sb.Append("<th>消费金额</th>");
            sb.Append("<th>卡付金额</th>");
            sb.Append("<th>现金支付</th>");
            sb.Append("<th>卡内余额</th>");
            sb.Append("<th>退款金额</th>");
            sb.Append("<th>退积分</th>");
            sb.Append("<th>本次积分</th>");
            sb.Append("<th>消费积分</th>");
            sb.Append("<th>总积分</th>");
            sb.Append("<th>充值金额</th>");
            sb.Append("<th>备注</th>");
            sb.Append("<th>折扣率</th>");
            sb.Append("<th>接待人</th>");
            sb.Append("</tr>");
            for (int i = 0; i < numPage; i++)
            {
                try
                {
                    int memberType = Convert.ToInt32(list[i].consumeType);
                    consumeMode = consume.GetByID(memberType);
                    sb.Append("<tr name=\"row\" onclick=\"xiangXi(this)\">");
                    sb.Append("<td>" + list[i].id + "</td>");
                    sb.Append("<td>" + list[i].operatorId + "</td>");
                    sb.Append("<td>" + list[i].memberCardId + "</td>");
                    sb.Append("<td>" + list[i].date + "</td>");
                    sb.Append("<td>" + consumeMode.solutionName + "</td>");
                    sb.Append("<td>" + list[i].consumeMoney + "</td>");
                    sb.Append("<td>" + list[i].cardPayMoney + "</td>");
                    sb.Append("<td>" + list[i].cashPayMoney + "</td>");
                    sb.Append("<td>" + list[i].cardBalance + "</td>");
                    sb.Append("<td>" + list[i].refundmentMoney + "</td>");
                    sb.Append("<td>" + list[i].exchangeIntegral + "</td>");
                    sb.Append("<td>" + list[i].exchangeIntegral + "</td>");
                    sb.Append("<td>" + list[i].consumeIntegral + "</td>");
                    sb.Append("<td>" + list[i].totalIntegral + "</td>");
                    sb.Append("<td>" + list[i].savingMoney + "</td>");
                    sb.Append("<td>" + list[i].details + "</td>");
                    sb.Append("<td>" + list[i].Discount + "</td>");
                    sb.Append("<td>" + list[i].jiedairen + "</td>");
                    sb.Append("</tr>");
                }
                catch (Exception)
                {

                    break;
                }

            }
            return Content(sb.ToString());
        }

        public ActionResult goodsInfoLoad(FormCollection fc)
        {
            int wasteBookID = Convert.ToInt32(fc["wasteBookId"]);
            goodsInfoManager goodsinfo = new goodsInfoManager();
            List<goodsInfo> list = goodsinfo.GetAll(wasteBookID);
            StringBuilder sb = new StringBuilder();
            goodsManager good = new goodsManager();
            goods goodsMode = new goods();

            sb.Append("<tr>");
            sb.Append("<th>商品编号</th>");
            sb.Append("<th>名称</th>");
            sb.Append("<th>单价</th>");
            sb.Append("<th>数量</th>");
            sb.Append("<th>消费日期</th>");
            sb.Append("<th>折扣</th>");
            sb.Append("<th>流水号</th>");
            sb.Append("</tr>");
            for (int i = 0; i < list.Count; i++)
            {
                goodsMode = good.getBygoodsId(list[i].gid);

                sb.Append("<tr>");
                sb.Append("<td>" + list[i].gid + "</td>");
                if (goodsMode == null)
                {
                    sb.Append("<td>未找到此编号的商品</td>");
                }
                else
                {
                    sb.Append("<td>" + good.getBygoodsId(list[i].gid).goodsName + "</td>");
                }
                sb.Append("<td>" + list[i].goodsprice + "</td>");
                sb.Append("<td>" + list[i].goodscount + "</td>");
                sb.Append("<td>" + list[i].selltime + "</td>");
                sb.Append("<td>" + list[i].zhekou + "</td>");
                sb.Append("<td>" + list[i].wasteBookId + "</td>");
                sb.Append("</tr>");
            }
            return Content(sb.ToString());
        }
        public ActionResult Update(FormCollection fc)
        {
            string id = fc["id"]; ;
            memberInfoManager member = new memberInfoManager();
            Model.memberInfo memberMode = new Model.memberInfo();
            consumeSolutionManager consume = new consumeSolutionManager();
            Model.consumeSolution consuMode = new Model.consumeSolution();
            memberMode = member.GetModel(id);
            StringBuilder sb = new StringBuilder();
            List<consumeSolution> list = new List<consumeSolution>();
            list = consume.GetAll().ToList<consumeSolution>();
            consuMode = consume.GetByID(Convert.ToInt32(memberMode.cardType));
            AreasManager area = new AreasManager();
            Areas areaMode = new Areas();
            areaMode = area.GetByID(Convert.ToInt32(memberMode.AreasID));
            List<Areas> listArea = area.GetAll().ToList<Areas>();
            sb.Append("<table id=\"Table3\"  cellspacing=\"0\" cellpadding=\"1\" width=\"400px\" border=\"0\" style=\" float:left;  margin-left:45px; margin-top:20px;\">");
            sb.Append("<tbody>");
            //第一行
            sb.Append("<tr>");
            sb.Append("<td>");
            sb.Append("会员卡号：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtMemberId\" value=\"" + memberMode.memberId + "\" type=\"text\" id=\"txtMemberId\"  style=\"width: 84%\" onchange=\"getClientInfo(this)\" onkeydown=\"return onKeyCustInfo(this)\" class=\" Line\" readonly>");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("会员姓名：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + memberMode.memberName + "\" type=\"text\" id=\"txtMemberName\" style=\"width:84%;\" class=\" Line\">");
            sb.Append("</td>");
            sb.Append("</tr>");

            sb.Append("<tr style=\"height:15px;\">");
            sb.Append("</tr>");

            //第二行
            sb.Append("<tr>");
            sb.Append("<td>");
            sb.Append("性    别：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<select name=\"_ctl0:WorkForm:sStatus\" id=\"cbxSex\" style=\"width:115px;\">");
            string sex = memberMode.sex.ToString();
            if (sex == "True")
            {
                sb.Append("<option selected=\"selected\" value=\"0\">男</option>");
                sb.Append("<option value=\"1\">女</option>");
            }
            else
            {
                sb.Append("<option  value=\"0\">男</option>");
                sb.Append("<option selected=\"selected\" value=\"1\">女</option>");
            }
            sb.Append("</select>");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("联系电话：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + memberMode.mobile + "\" type=\"text\" id=\"txtMobile\" style=\"width:84%;\" class=\" Line\">");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr style=\"height:15px;\">");
            sb.Append("</tr>");
            //第三行
            sb.Append("<tr>");
            sb.Append("<td>");
            sb.Append("座机号码：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + memberMode.Tel + "\" type=\"text\" id=\"txtTel\" style=\"width:84%;\" class=\" Line\">");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("电子邮件：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + memberMode.Email + "\" type=\"text\" id=\"txtEmail\" style=\"width:84%;\" class=\" Line\">");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr style=\"height:15px;\">");
            sb.Append("</tr>");
            //第四行
            sb.Append("<tr>");
            sb.Append("<td>");
            sb.Append("身份证号：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + memberMode.IDNumber + "\" type=\"text\" id=\"txtIDNumber\" style=\"width:84%;\" class=\" Line\">");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("出生日期：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + Convert.ToDateTime(memberMode.birthDay).ToString("yyyy-MM-dd") + "\" type=\"text\" id=\"txtBirthDay\" style=\"width:84%;\" class=\" Line\" onclick=\"WdatePicker()\">");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr style=\"height:15px;\">");
            sb.Append("</tr>");
            //第五行
            sb.Append("<tr>");
            sb.Append("<td>");
            sb.Append("卡片类型：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<select name=\"_ctl0:WorkForm:sStatus\" id=\"cbxCardType\" style=\"width:115px;\">");
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].id == memberMode.cardType)
                {
                    sb.Append("<option  value=\"" + list[i].id + "\" selected=\"selected\">" + list[i].solutionName + "</option>");
                }
                else
                {
                    sb.Append("<option  value=\"" + list[i].id + "\">" + list[i].solutionName + "</option>");
                }
            }

            sb.Append("</select>");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("卡内金额：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + memberMode.Balance + "\"  type=\"text\" id=\"txtBalance\" style=\"width:84%;\" class=\" Line\">");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr style=\"height:15px;\">");
            sb.Append("</tr>");
            //第六行
            sb.Append("<tr>");
            sb.Append("<td>");
            sb.Append("卡内积分：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" type=\"text\" id=\"txtPoint\" style=\"width:84%;\" value=\"" + memberMode.point + "\" class=\" Line\">");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("卡片状态：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<select name=\"_ctl0:WorkForm:sStatus\" id=\"cbxStatus\" style=\"width:115px;\">");
            if (memberMode.status == 0)
            {
                sb.Append("<option  value=\"0\" selected=\"selected\">正常</option>");
            }
            else
            {
                sb.Append("<option  value=\"0\">正常</option>");
            }
            if (memberMode.status == 1)
            {
                sb.Append("<option  value=\"1\" selected=\"selected\">挂失</option>");
            }
            else
            {
                sb.Append("<option  value=\"1\">挂失</option>");
            }
            if (memberMode.status == 2)
            {
                sb.Append("<option  value=\"2\" selected=\"selected\">停用</option>");
            }
            else
            {
                sb.Append("<option  value=\"2\">停用</option>");
            }
            sb.Append("</select>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr style=\"height:15px;\">");
            sb.Append("</tr>");

            //第七行
            sb.Append("<tr>");
            sb.Append("<td>");
            sb.Append("发卡日期：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + Convert.ToDateTime(memberMode.createDate).ToString("yyyy-MM-dd") + "\" type=\"text\" id=\"txtCreateDate\" style=\"width:84%;\" class=\" Line\" onclick=\"WdatePicker()\">");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("截止日期：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + Convert.ToDateTime(memberMode.expiresDate).ToString("yyyy-MM-dd") + "\" type=\"text\" id=\"txtExpiresDateDate\" style=\"width:84%;\" class=\" Line\" onclick=\"WdatePicker()\">");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr style=\"height:15px;\">");
            sb.Append("</tr>");
            //第八行
            sb.Append("<tr>");
            sb.Append("<td>");
            sb.Append("消费金额：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + memberMode.consume + "\" type=\"text\" id=\"txtConsume\" style=\"width:84%;\" class=\" Line\">");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("婚姻状况：");
            sb.Append("</td>");
            sb.Append("<td>");
            if (memberMode.Marriage == "未婚")
            {
                sb.Append("<input type=\"radio\" name=\"Marriage\" value=\"已婚\"  />已婚     ");
                sb.Append("<input type=\"radio\" name=\"Marriage\"checked=\"true\" value=\"未婚\" />未婚");
            }
            else
            {
                sb.Append("<input type=\"radio\" name=\"Marriage\" checked=\"true\" />已婚     ");
                sb.Append("<input type=\"radio\" name=\"Marriage\" />未婚");
            }
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr style=\"height:15px;\">");
            //第九行
            sb.Append("<tr>");
            sb.Append("<td>");
            sb.Append("邮政编码：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + memberMode.Zip + "\" type=\"text\" id=\"txtZip\" style=\"width:84%;\" class=\" Line\">");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("家庭住址：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + memberMode.Address + "\" type=\"text\" id=\"txtAddress\" style=\"width:84%;\" class=\" Line\">");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr style=\"height:15px;\">");
            sb.Append("</tr>");
            //第十行
            sb.Append("<tr>");
            sb.Append("<td>");
            sb.Append("区域名称：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<select name=\"_ctl0:WorkForm:sStatus\" id=\"cbxAreas\" style=\"width:115px;\">");
            for (int i = 0; i < listArea.Count(); i++)
            {
                if (listArea[i].id == memberMode.AreasID)
                {
                    sb.Append("<option  value=\"" + listArea[i].id + "\" selected=\"selected\">" + listArea[i].AreaName + "</option>");
                }
                else
                {
                    sb.Append("<option  value=\"" + listArea[i].id + "\">" + listArea[i].AreaName + "</option>");
                }
            }
            sb.Append("</select>");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("会员类型：");
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<select name=\"_ctl0:WorkForm:sStatus\" id=\"cbxMemberType\" style=\"width:115px;\">");
            if (memberMode.MemberType == "普通用户")
            {
                sb.Append("<option  value=\"普通用户\" selected=\"selected\">普通用户</option>");
            }
            else
            {
                sb.Append("<option  value=\"普通用户\">普通用户</option>");
            }
            if (memberMode.MemberType == "团购用户")
            {
                sb.Append("<option  value=\"团购用户\" selected=\"selected\">团购用户</option>");
            }
            else
            {
                sb.Append("<option  value=\"团购用户\">团购用户</option>");
            }
            if (memberMode.MemberType == "测试用户")
            {
                sb.Append("<option  value=\"测试用户\" selected=\"selected\">测试用户</option>");
            }
            else
            {
                sb.Append("<option  value=\"测试用户\">测试用户</option>");
            }

            sb.Append("</select>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr style=\"height:15px;\">");
            sb.Append("</tr>");
            //第十一行
            sb.Append("<tr>");
            sb.Append("<td>");
            sb.Append("备注：");
            sb.Append("</td>");
            sb.Append("<td colspan=\"3\">");
            sb.Append("<input name=\"_ctl0:WorkForm:txtCustRelation\" value=\"" + memberMode.memo + "\" type=\"text\" id=\"txtMemo\" style=\"width:84%;\" class=\" Line\">");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr style=\"height:15px;\">");
            sb.Append("</tr>");



            sb.Append("</tbody>");
            sb.Append("</table>");
            sb.Append("<img src=\"\\Image\\员工.png" + "\" width=\"150\" style=\" float:right;   margin-right:20px; margin-top:15px; \"  height=\"150\" alt=\"员工图\" ></img>");
            sb.Append("<a href=\"http://www.w3school.com.cn\"  style=\"color:red; text-decoration:underline; margin-left:65px;\">浏   览</a>");
            sb.Append("<div style=\"margin-top:240px; text-align:center;\">");
           
            sb.Append("<input  type=\"button\" value=\"确定\" onclick=\"update()\" class=\"button2\" style=\" margin-left:10px;\"/>");
            sb.Append("<input  type=\"button\" value=\"取消\" onclick=\"updateClose()\" class=\"button2\" style=\" margin-left:50px;\"/>");
            sb.Append("</div>");
            return Content(sb.ToString());
        }


        public ActionResult updateSubmit(FormCollection fc)
        {
            string MemberId = fc["MemberId"];
            string Name = fc["Name"];
            string Sex = fc["Sex"];
            string Mobile = fc["Mobile"];
            string Tel = fc["Tel"];
            string Email = fc["Email"];
            string IDNumber = fc["IDNumber"];
            string BirthDay = fc["BirthDay"];
            string CardType = fc["CardType"];
            string Balance = fc["Balance"];
            string Point = fc["Point"];
            string Status = fc["Status"];
            string CreateDate = fc["CreateDate"];
            string ExpiresDateDate = fc["ExpiresDateDate"];
            string Consume = fc["Consume"];
            string Marriage = fc["Marriage"];
            string Zip = fc["Zip"];
            string Address = fc["Address"];
            string Areas = fc["Areas"];
            string MemberType = fc["MemberType"];
            string Memo = fc["Memo"];
            memberInfoManager member = new memberInfoManager();
            memberInfo memberMode = new memberInfo();
            memberMode = member.GetModel(MemberId);
            memberMode.memberName = Name;
            memberMode.sex = Sex == "0" ? true : false;
            memberMode.mobile = Mobile;
            memberMode.Tel = Tel;
            memberMode.Email = Email;
            memberMode.IDNumber = IDNumber;
            memberMode.birthDay = Convert.ToDateTime(BirthDay);
            memberMode.cardType = Convert.ToInt32(CardType);
            memberMode.Balance = Convert.ToDecimal(Balance);
            memberMode.point = Convert.ToInt32(Point);
            memberMode.status = Convert.ToInt32(Status);
            memberMode.createDate = Convert.ToDateTime(CreateDate);
            memberMode.expiresDate = Convert.ToDateTime(ExpiresDateDate);
            memberMode.consume = Convert.ToDecimal(Consume);
            memberMode.Marriage = Marriage;
            memberMode.Zip = Zip;
            memberMode.Address = Address;
            memberMode.AreasID = Convert.ToInt32(Areas);
            memberMode.MemberType = MemberType;
            memberMode.memo = Memo;
            member.Update();
            return Content("修改成功！");
        }

        public ActionResult Load(FormCollection fc)
        {
            int numPage = Convert.ToInt32(fc["numPage"]);
            int CurrentPage = Convert.ToInt32(fc["CurrentPage"]);
            StringBuilder sb = new StringBuilder();
            memberInfoManager member = new memberInfoManager();
            consumeSolutionManager consume = new consumeSolutionManager();
            consumeSolution consumeMode = new consumeSolution();
            List<memberInfo> list = member.GetAll().ToList<memberInfo>();
            AreasManager area = new AreasManager();
            Areas areaMode = new Areas();
            sb.Append("<tr>");
            sb.Append("<th>");
            sb.Append("会员编号");
            sb.Append("</th>");
            sb.Append("<th>姓名</th><th>性别</th><th>联系电话</th><th>电话</th><th>电子邮箱</th><th>证件号码</th><th>出生日期</th><th>卡片类型</th><th>卡内余额</th><th>卡内积分</th><th>卡片状态</th><th>办卡日期</th><th>截止日期</th><th>消费金额</th><th>备注</th><th>婚姻状况</th><th>邮编</th><th>地址</th><th>地区</th><th>会员类型</th><th>推介人</th>");
            sb.Append("</tr>");
            for (int i = (CurrentPage - 1) * numPage; i < numPage * CurrentPage; i++)
            {
                try
                {
                string sex = "";
                if (list[i].sex == true)
                {
                    sex = "男";
                }
                else
                {
                    sex = "女";
                }
                string status = "";
                if (list[i].status == 0)
                {
                    status = "正常";
                }
                else if (list[i].status == 1)
                {
                    status = "挂失";
                }
                else if (list[i].status == 2)
                {
                    status = "停用";
                }
                sb.Append("<tr name=\"row\" oncontextmenu=\"vc(this)\" onclick=\"vc_memberId(this)\">");
                sb.Append("<td>");
                sb.Append(list[i].memberId);
                sb.Append("</td>");
                sb.Append("<td><a href=\"javascript:\" onclick=\"memberUpdate(" + list[i].memberId + ")\">" + list[i].memberName + "</a></td><td>" + sex + "</td><td>" + list[i].mobile + "</td><td>" + list[i].Tel + "</td><td>" + list[i].Email + "</td><td>" + list[i].IDNumber + "</td><td>" +Convert.ToDateTime(list[i].birthDay).ToString("yyyy-MM-dd") + "</td><td>" + consume.GetByID(Convert.ToInt32(list[i].cardType)).solutionName + "</td><td>" + Convert.ToDecimal(list[i].Balance).ToString("#0.00") + "</td><td>" + list[i].point + "</td><td>" + status + "</td><td>" +Convert.ToDateTime(list[i].createDate).ToString("yyyy-MM-dd") + "</td><td>" +Convert.ToDateTime(list[i].expiresDate).ToString("yyyy-MM-dd") + "</td><td>" +Convert.ToDecimal(list[i].consume).ToString("#0.00") + "</td><td>" + list[i].memo + "</td><td>" + list[i].Marriage + "</td><td>" + list[i].Zip + "</td><td>" + list[i].Address + "</td><td>" + area.GetByID(Convert.ToInt32(list[i].AreasID)).AreaName + "</td><td>" + list[i].MemberType + "</td><td>" + list[i].tuiguangren + "</td>");
              
               }
                catch (Exception)
                {

                    break;
                }
            }
            sb.Append("</tr>");

            return Content(sb.ToString());



        }
        public ActionResult CountPage_Load(FormCollection fc)
        {
            string numPage = fc["numPage"];
            memberInfoManager member = new memberInfoManager();
            List<memberInfo> list = member.GetAll().ToList<memberInfo>();
            int countPage = list.Count / Convert.ToInt32(numPage);
            int countPageYu = list.Count % Convert.ToInt32(numPage);
            if (countPageYu > 0)
            {
                countPage++;
            }
            return Content(countPage.ToString());
        }


        public ActionResult wasteBookpageCount(FormCollection fc)
        {
            wasteBookManager wasteMag = new wasteBookManager();
            string numPage = fc["numPage"];
            string memberId = fc["memberId"];
            List<wasteBook> list = wasteMag.GetAll(memberId).ToList<wasteBook>();
            int num = list.Count() / Convert.ToInt32(numPage);
            if (list.Count() % Convert.ToInt32(numPage) > 0)
            {
                num++;
            }
            return Content(num.ToString());
        }


        public ActionResult wastebookNextPageLoad(FormCollection fc)
        {
            string memberId = fc["memberId"];
            int numPage = Convert.ToInt32(fc["numPage"]);
            int CurrentPage = Convert.ToInt32(fc["CurrentPage"]);
            wasteBookManager wasteMag = new wasteBookManager();
            List<wasteBook> list = wasteMag.GetAll(memberId).ToList<wasteBook>();
            StringBuilder sb = new StringBuilder();
            consumeSolutionManager consume = new consumeSolutionManager();
            consumeSolution consumeMode = new consumeSolution();
            sb.Append("<tr>");
            sb.Append("<th>流水号</th>");
            sb.Append("<th>操作员</th>");
            sb.Append("<th>会员编号</th>");
            sb.Append("<th>时间</th>");
            sb.Append("<th>会员类型</th>");
            sb.Append("<th>消费金额</th>");
            sb.Append("<th>卡付金额</th>");
            sb.Append("<th>现金支付</th>");
            sb.Append("<th>卡内余额</th>");
            sb.Append("<th>退款金额</th>");
            sb.Append("<th>退积分</th>");
            sb.Append("<th>本次积分</th>");
            sb.Append("<th>消费积分</th>");
            sb.Append("<th>总积分</th>");
            sb.Append("<th>充值金额</th>");
            sb.Append("<th>备注</th>");
            sb.Append("<th>折扣率</th>");
            sb.Append("<th>接待人</th>");
            sb.Append("</tr>");
            for (int i = (CurrentPage - 1) * numPage; i < numPage * CurrentPage; i++)
            {
                try
                {
                    int memberType = Convert.ToInt32(list[i].consumeType);
                    consumeMode = consume.GetByID(memberType);
                    sb.Append("<tr name=\"row\" oncontextmenu=\"vb(this)\">");
                    sb.Append("<td>" + list[i].id + "</td>");
                    sb.Append("<td>" + list[i].operatorId + "</td>");
                    sb.Append("<td>" + list[i].memberCardId + "</td>");
                    sb.Append("<td>" + list[i].date + "</td>");
                    sb.Append("<td>" + consumeMode.solutionName + "</td>");
                    sb.Append("<td>" + list[i].consumeMoney + "</td>");
                    sb.Append("<td>" + list[i].cardPayMoney + "</td>");
                    sb.Append("<td>" + list[i].cashPayMoney + "</td>");
                    sb.Append("<td>" + list[i].cardBalance + "</td>");
                    sb.Append("<td>" + list[i].refundmentMoney + "</td>");
                    sb.Append("<td>" + list[i].refundmentIntegral + "</td>");
                    sb.Append("<td>" + list[i].exchangeIntegral + "</td>");
                    sb.Append("<td>" + list[i].consumeIntegral + "</td>");
                    sb.Append("<td>" + list[i].totalIntegral + "</td>");
                    sb.Append("<td>" + list[i].savingMoney + "</td>");
                    sb.Append("<td>" + list[i].details + "</td>");
                    sb.Append("<td>" + list[i].Discount + "</td>");
                    sb.Append("<td>" + list[i].jiedairen + "</td>");
                    sb.Append("</tr>");
                }
                catch (Exception)
                {

                    break;
                }

            }
            return Content(sb.ToString());
        }

        //删除指定会员
        public ActionResult DelMember(FormCollection fc)
        {
            string memberId = fc["memberId"];
            memberInfoManager manager = new memberInfoManager();
            if (!string.IsNullOrEmpty(memberId))
            {
                manager.Delmember(memberId);
                return Content("删除成功");
            }
            return View();
        }

        public ActionResult GetmemberId(FormCollection fc)
        {
          string memberId=  fc["memberId"];
          Session["memberId"] = memberId;
            return Content("");
        }
        [HttpPost]
        public ActionResult getOneMember(FormCollection fc)
        {
            memberInfo MI = new memberInfo(); 
            memberInfoManager MImanager = new memberInfoManager();
            consumeSolutionManager consume = new consumeSolutionManager();
            AreasManager area = new AreasManager();
            string memberCardId = fc["memberCardId"];
            MI = MImanager.GetModelByMemberCardId(memberCardId);
            StringBuilder sb = new StringBuilder();
            if (MI != null)
            {
                sb.Append("<tr>");
                sb.Append("<th>");
                sb.Append("会员编号");
                sb.Append("</th>");
                sb.Append("<th>姓名</th><th>性别</th><th>联系电话</th><th>电话</th><th>电子邮箱</th><th>证件号码</th><th>出生日期</th><th>卡片类型</th><th>卡内余额</th><th>卡内积分</th><th>卡片状态</th><th>办卡日期</th><th>截止日期</th><th>消费金额</th><th>备注</th><th>婚姻状况</th><th>邮编</th><th>地址</th><th>地区</th><th>会员类型</th><th>推介人</th>");
                sb.Append("</tr>");
                 string sex = "";
                if (MI.sex == true)
                {
                    sex = "男";
                }
                else
                {
                    sex = "女";
                }
                string status = "";
                if (MI.status == 0)
                {
                    status = "正常";
                }
                else if (MI.status == 1)
                {
                    status = "挂失";
                }
                else if (MI.status == 2)
                {
                    status = "停用";
                } 
                sb.Append("<tr name=\"row\" oncontextmenu=\"vc(this)\" onclick=\"vc_memberId(this)\">");
                sb.Append("<td>");
                sb.Append(MI.memberId);
                sb.Append("</td>");  
                sb.Append("<td><a href=\"javascript:\" onclick=\"memberUpdate(" + MI.memberId + ")\">" + MI.memberName + "</a></td><td>" + sex + "</td><td>" + MI.mobile + "</td><td>" + MI.Tel + "</td><td>" + MI.Email + "</td><td>" + MI.IDNumber + "</td><td>" + Convert.ToDateTime(MI.birthDay).ToString("yyyy-MM-dd") + "</td><td>" + consume.GetByID(Convert.ToInt32(MI.cardType)).solutionName + "</td><td>" + Convert.ToDecimal(MI.Balance).ToString("#0.00") + "</td><td>" + MI.point + "</td><td>" + status + "</td><td>" + Convert.ToDateTime(MI.createDate).ToString("yyyy-MM-dd") + "</td><td>" + Convert.ToDateTime(MI.expiresDate).ToString("yyyy-MM-dd") + "</td><td>" + MI.consume + "</td><td>" + MI.memo + "</td><td>" + MI.Marriage + "</td><td>" + MI.Zip + "</td><td>" + MI.Address + "</td><td>" + area.GetByID(Convert.ToInt32(MI.AreasID)).AreaName + "</td><td>" + MI.MemberType + "</td><td>" + MI.tuiguangren + "</td>");
                sb.Append("</tr>"); 
            }
            
            return Content(sb.ToString());
        }
    }
}
